/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ProyectoBienestarUniversitarioComfenalcoCulturalis.src.java.mvc.dao;

import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.LinkedList;
import mvc.modelos.Horario;

/**
 *
 * @author pezcado
 */
public class HorarioDAO extends Model implements IDAO<Horario> {
    
    private PreparedStatement consultar;
    private PreparedStatement insertar;
    private PreparedStatement modificar;
    private PreparedStatement eliminar;
    private PreparedStatement listar;
    private Model model; 

    public Horario consultar(int codigo) throws SQLException {
        model= Model.getInstance();
        String sql="select codigo, ubicacion, dia, hora, id, "
                + "estado, descripcion from Horario where codigo="+codigo;
        consultar=model.getCon().prepareStatement(sql);
        ResultSet resultSet= consultar.executeQuery();
        Horario horario= new Horario();
        
        try{
            resultSet.next();
            
            horario.setCodigo(resultSet.getInt("codigo"));
            horario.setUbicacion(resultSet.getString("ubicacion"));
            horario.setDia(resultSet.getString("dia"));
            horario.setHora(resultSet.getString("hora"));
            horario.setId(resultSet.getInt("id"));
            horario.setEstado(resultSet.getString("estado"));
            horario.setDescripcion(resultSet.getString("descripcion"));
            
            //return horario;
        }catch(Exception e){
            
        }
        return horario; 
        
    }

    public void insertar(Horario IDAO) throws SQLException {
        model= Model.getInstance();
        if(insertar==null){
            String sql="insert into Horario values(?,?,?,?,?,?,?)";
            insertar= model.getCon().prepareStatement(sql);
        }
        insertar.setInt(1, IDAO.getCodigo());
        insertar.setString(2, IDAO.getUbicacion());
        insertar.setString(3, IDAO.getDia());
        insertar.setString(4, IDAO.getHora());
        insertar.setInt(5, IDAO.getId());
        insertar.setString(6, IDAO.getEstado());
        insertar.setString(7, IDAO.getDescripcion());
        
        insertar.executeUpdate();
    }

    public void modificar(Horario IDAO) throws SQLException {
        model= Model.getInstance();
        String sql="update Horario set"
                + "ubicacion='"+IDAO.getUbicacion()+"',"
                + "dia='"+IDAO.getDia()+"',"
                + "hora='"+IDAO.getHora()+"',"
                //+ "id='"+IDAO.getId()+"',"
                + "estado='"+IDAO.getEstado()+"',"
                + "descripcion='"+IDAO.getDescripcion()+","
                + "where codigo="+IDAO.getCodigo();
        modificar=getCon().prepareStatement(sql);
        modificar.executeUpdate();
    }

    public void eliminar(Horario IDAO) throws SQLException {
        model= Model.getInstance();
        String sql="delete from Horario where codigo="+IDAO.getCodigo();
        eliminar=getCon().prepareStatement(sql);
        eliminar.executeUpdate();
    }

    public LinkedList<Horario> listar() throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
